//生成菜单
/*var menuItem = Vue.extend({
	name: 'menu-item',
	props:{item:{}},
	template:[
	          '<li>',
	          '<a v-if="item.type == 0" href="javascript:;">',
	          '<i v-if="item.icon != null" :class="item.icon"></i>',
	          '<span>{{item.name}}</span>',
	          '<i class="fa fa-angle-left pull-right"></i>',
	          '</a>',
	          '<ul v-if="item.type == 0" class="treeview-menu">',
	          '<menu-item :item="item" v-for="item in item.list"></menu-item>',
	          '</ul>',
	          '<a v-if="item.type == 1" :href="\'#\'+item.url"><i v-if="item.icon != null" :class="item.icon"></i><i v-else class="fa fa-circle-o"></i> {{item.name}}</a>',
	          '</li>'
	].join('')
});


var menuItem = Vue.extend({
	name: 'menu-item',
	props:{item:{}},
	template:[
		'<li>',
		'	<a v-if="item.type == 0" href="javascript:;">',
		'		<i v-if="item.icon != null" :class="item.icon"></i>',
		'		<span class="nav-label">{{item.name}}</span>',
		'		<span class="fa arrow"></span>',
		'	</a>',
		'	<ul v-if="item.type == 0" class="nav nav-second-level collapse">',
		'		<menu-item :item="item" v-for="item in item.list"></menu-item>',
		'	</ul>',
		'	<a v-if="item.type == 1" :href="\'#\'+item.url">{{item.name}}',
		'	</a>',
		'</li>'
	].join('')
});

 */

//iframe自适应
/*
$(window).on('resize', function() {
	var $content = $('.content');
	$content.height($(this).height() - 120);
	$content.find('yciframe').each(function() {
		$(this).height($content.height());
	});
}).resize();
*/

///注册菜单组件
// ue.component('menuItem',menuItem);

var vm = new Vue({
	el:'#wrapper',
	data:{
		user:{},
		menuList:{},
		main:"main.html",
		password:'',
		newPassword:''
	},
	methods: {
		getMenuList: function () {
			$.getJSON(baseURL + "sysMenu/queryUserMenuList", function(r){
				vm.menuList = r.menuList;
                window.permissions = r.permissions;
			});
		},
		getUser: function(){
			$.getJSON(baseURL + "sysUser/info", function(r){
				vm.user = r.user;
			});
		},
        logout: function () {
			//删除本地token
            localStorage.removeItem("token");
            //跳转到登录页面
            location.href = baseURL + 'login.html';
        }
	},
	created: function(){
		this.getUser();
		this.getMenuList();
	}
});


$(document).ready(function () {
	// 获取data
	$.ajax({
		type: "GET",
		url: baseURL + "sysMenu/queryUserMenuList",
		dataType: "json",
		success: function(r){
			var menuList = r.menuList;
			if (menuList != null && menuList.length > 0) {
				for (var i = 0;i<menuList.length;i++){
					var oneMenu = menuList[i];
					var str ='<li>';
					var twoMenuList = oneMenu.children;
					if(twoMenuList != null && twoMenuList.length>0){
						str+='<a href="javascript:;">'+
							' 	<i class="'+oneMenu.icon+'"></i>'+
							'	<span class="nav-label">'+oneMenu.name+'</span>'+
							'	<span class="fa arrow"></span>'+
							'</a>';

						str += '<ul class="nav nav-second-level collapse">';
						for (var j=0;j<twoMenuList.length;j++){
							var twoMenu = twoMenuList[j];
							str+='<li><a href="'+twoMenu.url+'" target="yciframe">'+twoMenu.name+'</a></li>';
						}
						str += '</ul>';
					} else {
						str += '<a href="'+oneMenu.url+'" target="yciframe">'+
							'		<i class="'+oneMenu.icon+'"></i>'+
							'		<span class="nav-label">'+oneMenu.name+'</span>'+
							'	</a>';
					}
					str += "</li>";
					$("#side-menu").append(str);
				}
				// MetsiMenu
				$('#side-menu').metisMenu();
			}
		}
	});
});
